home *** CD-ROM | disk | FTP | other *** search
- Path: longwood.cs.ucf.edu!not-for-mail
- From: schnitzi@longwood.cs.ucf.edu (Mark Schnitzius)
- Newsgroups: comp.lang.c
- Subject: Re: Sorting large files
- Date: 31 Jan 1996 08:46:10 -0500
- Organization: University of Central Florida
- Message-ID: <4enrr2$ofn@longwood.cs.ucf.edu>
- References: <4e8j9b$cuf@longwood.cs.ucf.edu> <4elhik$cpq@ibm32.perftech.com>
- NNTP-Posting-Host: longwood.cs.ucf.edu
-
- murf@perftech.com (John Murphy) writes:
-
- >In article <4e8j9b$cuf@longwood.cs.ucf.edu>, schnitzi@longwood.cs.ucf.edu
- >says...
- >>
- >>There was some discussion here a little while
- >>back on how to sort the lines in a large file
- >>without having to have a huge character array.
- >>I suggested using ftell and fseek to hunt down
- >>the particular lines you are comparing.
-
- >Who says computer people don't have a sense of humor?!
-
- >Least any neophytes miss the joke and take this as a serious solution to the
- >sorting problem, perhaps we should point out that while this code will
- >compile and run and even (eventually) sort a file, it's practical use will
- >be limited by the MTBF of your equipment and/or your life expectancy ---
- >it's SLOOOW! Any file I/O operation is time consuming, and depending on the
- >file system, random file I/O can be VERY time consuming; with MS-DOS, for
- >instance, reading a large file backwards is an N-squared operation.
-
- It was really only half tongue-in-cheek. I would compare it to
- using an insertion sort -- it's much slower than, say, quicksort,
- but still has its practical uses. Namely, it is much, much easier
- to code than a merge sort that creates intermediate files. If I
- had to sort a large file in a hurry and didn't have access to any
- system sort routines, I would use the fseek/ftell trick.
-
- This is not to say that it is any substitute for doing a multi-file
- merge sort if speed is an issue. Others have pointed out other
- practical limitations to it as well; such as the fact that it won't
- work for a million-line file.
-
- >As a sanity check on the practicality of this method of sorting, try sorting
- >a 20,000 byte file; that's a file that would require the same amount of
- >memory as the array of 5000 longs. On one of my systems, using this code to
- >sort a file of 250 80 bytes records took 17:30 minutes; sorting the same
- >file with MS-DOS SORT (a very slow sort program) took 0.8 seconds.
-
- Interesting!
-
-
-
- _____________________________________________________________
- mark schnitzius - - - - - - - - - - - - - schnitzi@mentos.com
- - - - -<a href="http://east.isx.com/~schnitzi/">me</a>- - - -
-